/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.evl.tecinfo.gui;

import br.com.evl.tecinfo.modelo.ApenasLetrasMaiusculaseMinuscula;
import br.com.evl.tecinfo.modelo.Area;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Locale;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Tecinfo
 */
public class CadastroArea extends javax.swing.JFrame {

    private int clicou_ok;
    private int linha_editar = -1;
    private ArrayList<JCheckBox> areasJCheckBox = new ArrayList();

    /**
     * Creates new form cadastroarea
     */
    public CadastroArea() {
        initComponents();        
        setLocationRelativeTo(this);
        setSize(350, 320);
        setTitle("Cadastrar Área");
        
        JTextField textFieldArea = new JTextField();
        jFormattedTextField_Nome.setDocument(new ApenasLetrasMaiusculaseMinuscula(20));
        
        //IMAGEM ÍCONE
        ImageIcon icone = new ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/icon64x64.png"));
        setIconImage(icone.getImage());     
        
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel_cadastoarea = new javax.swing.JLabel();
        jLabelNomeArea = new javax.swing.JLabel();
        jLabelNumeroArea = new javax.swing.JLabel();
        jButton1cadastra_area = new javax.swing.JButton();
        jButton2editar_area = new javax.swing.JButton();
        jButton3cancelar_area = new javax.swing.JButton();
        jSpinnerNumeroArea = new javax.swing.JSpinner();
        jFormattedTextField_Nome = new javax.swing.JFormattedTextField();
        jLabelIMGCadastrarArea = new javax.swing.JLabel();
        jLabelIMGBacgroundArea = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel_cadastoarea.setFont(new java.awt.Font("Century Gothic", 0, 15)); // NOI18N
        jLabel_cadastoarea.setForeground(new java.awt.Color(102, 102, 102));
        jLabel_cadastoarea.setText("CADASTRAR ÁREA");
        getContentPane().add(jLabel_cadastoarea);
        jLabel_cadastoarea.setBounds(110, 30, 140, 30);

        jLabelNomeArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jLabelNomeArea.setText("Nome:");
        getContentPane().add(jLabelNomeArea);
        jLabelNomeArea.setBounds(30, 140, 39, 25);

        jLabelNumeroArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jLabelNumeroArea.setText("Número:");
        getContentPane().add(jLabelNumeroArea);
        jLabelNumeroArea.setBounds(30, 100, 50, 25);

        jButton1cadastra_area.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jButton1cadastra_area.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/conformado20x20.png"))); // NOI18N
        jButton1cadastra_area.setText("CADASTRAR");
        jButton1cadastra_area.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1cadastra_areaActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1cadastra_area);
        jButton1cadastra_area.setBounds(30, 220, 130, 30);

        jButton2editar_area.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jButton2editar_area.setText("Editar");
        getContentPane().add(jButton2editar_area);
        jButton2editar_area.setBounds(0, 0, 0, 0);

        jButton3cancelar_area.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jButton3cancelar_area.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/sair20x20.png"))); // NOI18N
        jButton3cancelar_area.setText("CANCELAR");
        jButton3cancelar_area.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3cancelar_areaActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3cancelar_area);
        jButton3cancelar_area.setBounds(180, 220, 130, 30);

        jSpinnerNumeroArea.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10, 1));
        getContentPane().add(jSpinnerNumeroArea);
        jSpinnerNumeroArea.setBounds(90, 100, 90, 30);
        getContentPane().add(jFormattedTextField_Nome);
        jFormattedTextField_Nome.setBounds(90, 140, 220, 30);

        jLabelIMGCadastrarArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/CADASTRODEUSUARIO.png"))); // NOI18N
        getContentPane().add(jLabelIMGCadastrarArea);
        jLabelIMGCadastrarArea.setBounds(80, 20, 210, 50);

        jLabelIMGBacgroundArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/backgroud.jpg"))); // NOI18N
        getContentPane().add(jLabelIMGBacgroundArea);
        jLabelIMGBacgroundArea.setBounds(0, 0, 360, 290);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1cadastra_areaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1cadastra_areaActionPerformed

        ArrayList <Area> areas = new ArrayList<>();
        Area nArea = new Area();
        nArea.setNumero((int) jSpinnerNumeroArea.getValue());
        areas.add(nArea);
        
        boolean numerovazio = false;
        boolean nomevazio = false;
        //CÓDIGO PARA CHECAR SE OS CAMPOS DO CADASTROS E ALTERAR COR DOS CAMPOS VAZIOS
        if (linha_editar == -1) {
            if (jSpinnerNumeroArea.getValue() == 0) {
                jSpinnerNumeroArea.setForeground(new Color(255, 0, 51));
                numerovazio = true;
            } else {
                jSpinnerNumeroArea.setForeground(new Color(0, 0, 0));
                numerovazio = false;
            }
            if (jFormattedTextField_Nome.getText().equals("")) {
                jFormattedTextField_Nome.setBackground(new Color(255, 209, 209));
                nomevazio = true;
            } else {
                jFormattedTextField_Nome.setBackground(new Color(255, 255, 255));
                nomevazio = false;
            }
            // CHECANDO SE EXISTE CAMPOS VAZIOS
            if (nomevazio == true || numerovazio == true) {
                java.awt.Toolkit.getDefaultToolkit().beep();
                JOptionPane.showMessageDialog(null, "Exite campos vazios!");
                // CHECANDO SE OS CAMPOS ESTÃO PREENCHIDOS 
            } else if (nomevazio == false && numerovazio == false) {
                //CONFIRMAÇÃO DE CADASTRO
                clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja CADASTRAR a Área?", "Confirmação", JOptionPane.YES_NO_OPTION);
                if (clicou_ok == JOptionPane.YES_OPTION) {
                    
                    
                    //CADASTRO CONCLUÍDO -----------------
                    JOptionPane.showMessageDialog(null, "Área cadastrada com sucesso!");
                    jFormattedTextField_Nome.setText("");
                    jSpinnerNumeroArea.setValue(0);
                    //DESEJA CONTINUAR CADASTRANDO?
                    clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja continuar?", "Confirmação", JOptionPane.YES_NO_OPTION);
                    if (clicou_ok == JOptionPane.YES_OPTION) {
                    } else if (clicou_ok == JOptionPane.NO_OPTION) {
                        this.dispose();
                    }
                } else if (clicou_ok == JOptionPane.NO_OPTION) {
                }
            }
        }
    }//GEN-LAST:event_jButton1cadastra_areaActionPerformed

    private void jButton3cancelar_areaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3cancelar_areaActionPerformed
        clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja cancelar o cadastramento da área?", "Confirmação", JOptionPane.YES_NO_OPTION);
        if (clicou_ok == JOptionPane.YES_OPTION) {
            this.dispose();

        } else if (clicou_ok == JOptionPane.NO_OPTION) {
        }
    }//GEN-LAST:event_jButton3cancelar_areaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CadastroArea().setVisible(true);

            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1cadastra_area;
    private javax.swing.JButton jButton2editar_area;
    private javax.swing.JButton jButton3cancelar_area;
    private javax.swing.JFormattedTextField jFormattedTextField_Nome;
    private javax.swing.JLabel jLabelIMGBacgroundArea;
    private javax.swing.JLabel jLabelIMGCadastrarArea;
    private javax.swing.JLabel jLabelNomeArea;
    private javax.swing.JLabel jLabelNumeroArea;
    private javax.swing.JLabel jLabel_cadastoarea;
    private javax.swing.JSpinner jSpinnerNumeroArea;
    // End of variables declaration//GEN-END:variables
}
